//
//  DetailViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/6/30.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "DetailViewController.h"
#import "DetailTableViewCell.h"
#import "TraderInfoModel.h"

@interface DetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UIImageView * backImageView;

@property (nonatomic, strong)UITableView * tableView;

@property (nonatomic, strong)NSArray<TraderInfoModel *> * traderInfoList;

@end

@implementation DetailViewController


- (void)setTraderInfoList:(NSArray<TraderInfoModel *> *)traderInfoList{
    
    _traderInfoList = traderInfoList;
    
    [self.tableView reloadData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [TraderInfoModel traderInfoStringWithSucess:^(NSArray<TraderInfoModel *> *array) {
        
        self.traderInfoList = array;
    } error:^{
        
        NSLog(@"traderInfoList error");
    }];
    
    [self setupNavBar];
    [self setupUI];
}

- (void)setupNavBar{
    
    self.title = @"明细";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToAccountView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    //    最后一行cell显示
    [self.tableView setFrame: CGRectMake(self.tableView.frame.origin.x , self.tableView.frame.origin.y , self.tableView.frame.size.width , self.tableView.frame.size.height-120)];
    
    self.view.backgroundColor = [UIColor blackColor];
    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    self.tableView.bounces = NO;
    
    [self.tableView registerClass:[DetailTableViewCell class] forCellReuseIdentifier:@"DetailCell"];
    
    [self.view addSubview:self.tableView];
    
}


- (void)viewDidLayoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.view);
    }];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.traderInfoList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCell" forIndexPath:indexPath];
    
    TraderInfoModel * model = self.traderInfoList[indexPath.row];
    
    cell.model = model;
//    cell.dateLabel.text = @"2017.06.01";
//    cell.timeLabel.text = @"16:59:43";
//    cell.subTltleLabel.text = @"入金";
//    cell.moneyLabel.text = @"+$300.00";
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 83 * SCREENH6;
    
}



- (void)backToAccountView{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
